<?php

class Authors extends MY_Model
{
	/**
	* Liste les membres
	* @param from int start de la recherche
	* @param nb_result int nombre de résultat souhaité
	* @param login string Login qu'on veut recherche
	*/
	public function search($from = 0, $to = 10, $pseudo = null)
	{
		$CI =& get_instance();
		$sKey = "search_authors".($pseudo ? '_'.$pseudo : '');
		$result = $CI->my_cache->get(
						$sKey,
						array($this, "searchDB"),
						array($from, $to, $pseudo)
					);
		var_dump($result);
		return $result;
	}

	public function searchDB($from = 0, $to = 10, $pseudo = null) {
		$CI =& get_instance();
		$where = $pseudo ? array("pseudo" => $pseudo) : array();
		$query = $CI->db->order_by("pseudo")
						->get_where('authors', $where, $to, $from);
		if($query->num_rows() == 0) {
			return array();
		}
		$authors = array();
		foreach ($query->result_array() as $row) {
			$authors[] = $this->getObject($row, 'author');
		}
		return $authors;
	}

}
